package com.ymatou.operate.trading.api.testcase;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;

import org.json.JSONArray;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.trading.operate.parameter.OrderGroupVo;
import com.ymatou.iapi.trading.operate.parameter.OrderItemVo;
import com.ymatou.iapi.trading.operate.parameter.OrderVo;
import com.ymatou.iapi.trading.operate.parameter.PlaceOrderResp;
import com.ymatou.iapi.trading.operate.parameter.SellerCouponVo;
import com.ymatou.iapi.trading.operate.parameter.YmatouCouponVo;
import com.ymatou.iapi.trading.operate.parameter.enums.AppTerminalSourceEnum;
import com.ymatou.iapi.trading.operate.parameter.enums.LogisticsTypeEnum;
import com.ymatou.iapi.trading.operate.parameter.enums.OrderTypeEnum;
import com.ymatou.iapi.trading.operate.parameter.enums.PriceTypeEnum;
import com.ymatou.iapi.trading.operate.parameter.enums.ProductRefundChannelEnum;
import com.ymatou.iapi.trading.operate.parameter.enums.SalesTypeEnum;
import com.ymatou.iapi.trading.operate.parameter.enums.SellerCouponApplianceTypeEnum;
import com.ymatou.iapi.trading.operate.parameter.enums.TerminalSourceEnum;
import com.ymatou.iapi.trading.operate.parameter.enums.YmatouCouponApplianceTypeEnum;
import com.ymatou.iapi.trading.operate.parameter.req.PlaceOrderReq;
import com.ymatou.iapi.trading.operate.service.PlaceOrderCall;
import com.ymatou.operate.trading.api.parameter.CancelOrderBean;
import com.ymatou.operate.trading.api.service.CancelOrderCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P3;
import com.ymttest.business.service.CouponCallService;
import com.ymttest.business.service.OrderCallService;
import com.ymttest.business.service.PayGateWayCallService;
import com.ymttest.business.service.ProductCallService;
import com.ymttest.common.enums.CancelOrderTypeEnum;
import com.ymttest.database.model.YmtAccountEntry;
import com.ymttest.database.model.YmtCouponPrivateUserBound;
import com.ymttest.database.sqlwapper.AccountDefaultWapper;
import com.ymttest.database.sqlwapper.DefaultWapper;
import com.ymttest.database.sqlwapper.YmtCouponPrivateUserBoundWapper;
import com.ymttest.database.sqlwapper.YmtCouponWapper;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.constant.ECode;

/**
 * 取消订单 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_CancelOrder {
	private static CancelOrderBean cancelorderbean;

	private static CancelOrderCall cancelordercall;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("取消订单");
	}

	@Before
	public void caseUp() {
		cancelorderbean = new CancelOrderBean();
		cancelordercall = new CancelOrderCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(cancelordercall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	// 创建一个订单，使用平台优惠券,商家优惠券
	private Map placeOrder() {
		Map map = new HashMap();
		try {
			PlaceOrderReq placeorderBean = new PlaceOrderReq();
			PlaceOrderCall placeorderCall = new PlaceOrderCall();
			int userId = Integer.valueOf(EnvSetup.getData("BuyUserId"));
			int sellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
			// 创建产品
			Logger.comment("前置数据准备");
			HashMap<String, Object> productInfo = ProductCallService
					.createProduct(sellerId, 3);
			Logger.comment("前置数据准备结束");
			String productId = (String) productInfo.get("productId");
			Logger.debug("productId:" + productId);
			String productName = (String) productInfo.get("productName");
			String pic = (String) productInfo.get("pic");
			BigDecimal price = (BigDecimal) (productInfo.get("price"));
			String catalogId = (String) productInfo.get("catalogId");
			YmatouCouponVo ymtCoupon = new YmatouCouponVo();
			// 平台优惠券
			BigDecimal couponValue = new BigDecimal(13);
			String couponCode = new OrderCallService().receivePlatformCoupon(
					userId, couponValue);
			ymtCoupon.setApplianceType(YmatouCouponApplianceTypeEnum.ALL);
			ymtCoupon.setCouponCode(couponCode);
			ymtCoupon.setCouponValue(couponValue);
			placeorderBean.setAppId("AutoTest");
			placeorderBean.setYmatouCoupon(ymtCoupon);
			placeorderBean.setUserId(userId);
			placeorderBean.setRequestId(TestDataManager.getRandomUUID()
					.toString());
			placeorderBean.setTerminalSource(TerminalSourceEnum.IOS);
			placeorderBean.setAppTerminalSource(AppTerminalSourceEnum.Phone);
			OrderGroupVo groupVo1 = new OrderGroupVo();
			// 商家优惠券
			BigDecimal sellerCouponValue = new BigDecimal(15);
			String sellerCouponCode = new CouponCallService()
					.receiveCouponInfo(sellerId, userId, couponValue);
			SellerCouponVo sellerCoupon = new SellerCouponVo();
			sellerCoupon.setApplianceType(SellerCouponApplianceTypeEnum.ALL);
			sellerCoupon.setCouponCode(sellerCouponCode);
			sellerCoupon.setCouponValue(sellerCouponValue);
			groupVo1.setSellerCoupon(sellerCoupon);
			groupVo1.setSellerId(sellerId);

			List<OrderVo> orders = new ArrayList<OrderVo>();
			OrderVo ordervo1 = new OrderVo();
			ordervo1.setAutoCancelOrderHours(new BigDecimal(1));
			ordervo1.setOrderType(OrderTypeEnum.Spot);
			ordervo1.setPaidFull(true);

			List<OrderItemVo> items = new ArrayList<OrderItemVo>();
			OrderItemVo orderitem1 = new OrderItemVo();
			orderitem1.setProductNum(1);
			orderitem1.setProductName(productName);
			orderitem1.setPriceType(PriceTypeEnum.VipPrice);
			orderitem1.setProductId(productId);
			price = new BigDecimal(210);
			orderitem1.setEarnestPrice(price);
			orderitem1.setProductPrice(price);
			orderitem1.setOriginalPrice(price);
			orderitem1.setSalesType(SalesTypeEnum.AlreadyInStock);
			orderitem1.setLogisticsType(LogisticsTypeEnum.SailProtect);
			orderitem1
					.setProductRefundChannel(ProductRefundChannelEnum.Official);
			items.add(orderitem1);
			ordervo1.setOrderItems(items);
			ordervo1.setFreight(new BigDecimal("21"));

			orders.add(ordervo1);
			groupVo1.setOrders(orders);
			placeorderBean.setOrderGroups(Arrays.asList(groupVo1));
			placeorderCall.setData(false, placeorderBean);
			placeorderCall.callService();

			YmtCouponPrivateUserBoundWapper ymtCouponPrivate = new YmtCouponPrivateUserBoundWapper();
			List<YmtCouponPrivateUserBound> listCoupon = ymtCouponPrivate
					.selectBysCouponCode(couponCode);
			int ymtBeforeCount = listCoupon.get(0).getiCouponUsedCount();
			List<YmtCouponPrivateUserBound> listCoupon2 = ymtCouponPrivate
					.selectBysCouponCode(sellerCouponCode);
			int sellerBeforeCount = listCoupon2.get(0).getiCouponUsedCount();

			map.put("orderId", placeorderCall.getOrderIds().get(0));
			map.put("tradingId", placeorderCall.getTradingId());
			map.put("ymtCouponCode", couponCode);
			map.put("sellerCouponCode", sellerCouponCode);
			map.put("ymtBeforeCount", ymtBeforeCount);
			map.put("sellerBeforeCount", sellerBeforeCount);
		} catch (Exception e) {
			Logger.fail(e);
		}
		return map;
	}

	// 创建一个买手2个订单，使用平台优惠券
	private Map placeOrder2() {
		Map map = new HashMap();
		try {
			PlaceOrderReq placeorderBean = new PlaceOrderReq();
			PlaceOrderCall placeorderCall = new PlaceOrderCall();
			int userId = Integer.valueOf(EnvSetup.getData("BuyUserId"));
			int sellerId = Integer.valueOf(EnvSetup.getData("SellerId"));

			String productName = "auto自动化测试";
			String pic = "http://p243.img.ymatou.com:10243/upload/productdes/3afa103d4ec4466f824b9f0458d6f4e2.jpg";
			BigDecimal price = new BigDecimal(130);
			String productId = "auto123456";
			YmatouCouponVo ymtCoupon = new YmatouCouponVo();
			// 平台优惠券
			BigDecimal couponValue = new BigDecimal(13);
			String couponCode = new OrderCallService().receivePlatformCoupon(
					userId, couponValue);
			ymtCoupon.setApplianceType(YmatouCouponApplianceTypeEnum.ALL);

			ymtCoupon.setCouponCode(couponCode);
			ymtCoupon.setCouponValue(couponValue);
			placeorderBean.setAppId("AutoTest");
			placeorderBean.setYmatouCoupon(ymtCoupon);
			placeorderBean.setUserId(userId);
			placeorderBean.setRequestId(TestDataManager.getRandomUUID()
					.toString());
			placeorderBean.setTerminalSource(TerminalSourceEnum.IOS);
			placeorderBean.setAppTerminalSource(AppTerminalSourceEnum.Phone);
			OrderGroupVo groupVo1 = new OrderGroupVo();
			// 商家优惠券
			BigDecimal sellerCouponValue = new BigDecimal(15);
			String sellerCouponCode = new CouponCallService()
					.receiveCouponInfo(sellerId, userId, couponValue);

			SellerCouponVo sellerCoupon = new SellerCouponVo();
			sellerCoupon.setApplianceType(SellerCouponApplianceTypeEnum.ALL);
			sellerCoupon.setCouponCode(sellerCouponCode);
			sellerCoupon.setCouponValue(sellerCouponValue);
			groupVo1.setSellerCoupon(sellerCoupon);
			groupVo1.setSellerId(sellerId);
			List<OrderVo> orders = new ArrayList<OrderVo>();
			OrderVo ordervo1 = new OrderVo();
			ordervo1.setAutoCancelOrderHours(new BigDecimal(1));
			ordervo1.setOrderType(OrderTypeEnum.Spot);
			ordervo1.setPaidFull(true);

			List<OrderItemVo> items = new ArrayList<OrderItemVo>();
			OrderItemVo orderitem1 = new OrderItemVo();
			orderitem1.setProductNum(1);
			orderitem1.setProductName(productName);
			orderitem1.setPriceType(PriceTypeEnum.VipPrice);
			orderitem1.setProductId(productId);
			orderitem1.setCatalogId(TestDataManager.getRandomUUID().toString());
			price = new BigDecimal(210);
			orderitem1.setEarnestPrice(price);
			orderitem1.setProductPrice(price);
			orderitem1.setOriginalPrice(price);
			orderitem1.setSalesType(SalesTypeEnum.AlreadyInStock);
			orderitem1.setLogisticsType(LogisticsTypeEnum.SailProtect);
			orderitem1
					.setProductRefundChannel(ProductRefundChannelEnum.Official);
			items.add(orderitem1);
			ordervo1.setOrderItems(items);
			ordervo1.setFreight(new BigDecimal("21"));

			// 第二个订单
			orders.add(ordervo1);
			orders.add(ordervo1);

			groupVo1.setOrders(orders);

			placeorderBean.setOrderGroups(Arrays.asList(groupVo1));
			placeorderCall.setData(placeorderBean);
			placeorderCall.callService();

			YmtCouponPrivateUserBoundWapper ymtCouponPrivate = new YmtCouponPrivateUserBoundWapper();
			List<YmtCouponPrivateUserBound> listCoupon = ymtCouponPrivate
					.selectBysCouponCode(couponCode);
			int ymtBeforeCount = listCoupon.get(0).getiCouponUsedCount();
			List<YmtCouponPrivateUserBound> listCoupon2 = ymtCouponPrivate
					.selectBysCouponCode(sellerCouponCode);
			int sellerBeforeCount = listCoupon2.get(0).getiCouponUsedCount();

			map.put("orderId", placeorderCall.getOrderIds());
			map.put("tradingId", placeorderCall.getTradingId());
			map.put("ymtCouponCode", couponCode);
			map.put("sellerCouponCode", sellerCouponCode);
			map.put("ymtBeforeCount", ymtBeforeCount);
			map.put("sellerBeforeCount", sellerBeforeCount);
		} catch (Exception e) {
			Logger.fail(e);
		}
		return map;
	}

	// 创建2个买手多个订单，使用平台优惠券,商家券
	private Map placeOrder3() {
		Map map = new HashMap();
		try {
			PlaceOrderReq placeorderBean = new PlaceOrderReq();
			PlaceOrderCall placeorderCall = new PlaceOrderCall();
			int userId = Integer.valueOf(EnvSetup.getData("BuyUserId"));
			int sellerId = Integer.valueOf(EnvSetup.getData("SellerId"));

			String productName = "auto自动化测试";
			String pic = "http://p243.img.ymatou.com:10243/upload/productdes/3afa103d4ec4466f824b9f0458d6f4e2.jpg";
			BigDecimal price = new BigDecimal(130);
			String productId = "auto123456";
			YmatouCouponVo ymtCoupon = new YmatouCouponVo();
			// 平台优惠券
			BigDecimal couponValue = new BigDecimal(13);
			String couponCode = new OrderCallService().receivePlatformCoupon(
					userId, couponValue);
			ymtCoupon.setApplianceType(YmatouCouponApplianceTypeEnum.ALL);

			ymtCoupon.setCouponCode(couponCode);
			ymtCoupon.setCouponValue(couponValue);
			placeorderBean.setAppId("AutoTest");
			placeorderBean.setYmatouCoupon(ymtCoupon);
			placeorderBean.setUserId(userId);
			placeorderBean.setRequestId(TestDataManager.getRandomUUID()
					.toString());
			placeorderBean.setTerminalSource(TerminalSourceEnum.IOS);
			placeorderBean.setAppTerminalSource(AppTerminalSourceEnum.Phone);
			OrderGroupVo groupVo1 = new OrderGroupVo();
			// 商家优惠券
			BigDecimal sellerCouponValue = new BigDecimal(15);
			String sellerCouponCode = new CouponCallService()
					.receiveCouponInfo(sellerId, userId, couponValue);

			SellerCouponVo sellerCoupon = new SellerCouponVo();
			sellerCoupon.setApplianceType(SellerCouponApplianceTypeEnum.ALL);
			sellerCoupon.setCouponCode(sellerCouponCode);
			sellerCoupon.setCouponValue(sellerCouponValue);
			groupVo1.setSellerCoupon(sellerCoupon);
			groupVo1.setSellerId(sellerId);
			List<OrderVo> orders = new ArrayList<OrderVo>();
			OrderVo ordervo1 = new OrderVo();
			ordervo1.setAutoCancelOrderHours(new BigDecimal(1));
			ordervo1.setOrderType(OrderTypeEnum.Spot);
			ordervo1.setPaidFull(true);

			List<OrderItemVo> items = new ArrayList<OrderItemVo>();
			OrderItemVo orderitem1 = new OrderItemVo();
			orderitem1.setProductNum(1);
			orderitem1.setProductName(productName);
			orderitem1.setPriceType(PriceTypeEnum.VipPrice);
			orderitem1.setProductId(productId);
			orderitem1.setCatalogId(TestDataManager.getRandomUUID().toString());
			price = new BigDecimal(210);
			orderitem1.setEarnestPrice(price);
			orderitem1.setProductPrice(price);
			orderitem1.setOriginalPrice(price);
			orderitem1.setSalesType(SalesTypeEnum.AlreadyInStock);
			orderitem1.setLogisticsType(LogisticsTypeEnum.SailProtect);
			orderitem1
					.setProductRefundChannel(ProductRefundChannelEnum.Official);
			items.add(orderitem1);
			ordervo1.setOrderItems(items);
			ordervo1.setFreight(new BigDecimal("71"));

			// 第二个订单
			orders.add(ordervo1);
			orders.add(ordervo1);
			groupVo1.setOrders(orders);

			// 买手2
			OrderGroupVo groupVo2 = new OrderGroupVo();
			// 商家优惠券
			BigDecimal sellerCouponValue2 = new BigDecimal(15);
			String sellerCouponCode2 = new CouponCallService()
					.receiveCouponInfo(sellerId, userId, couponValue);
			SellerCouponVo sellerCoupon2 = new SellerCouponVo();
			sellerCoupon2.setApplianceType(SellerCouponApplianceTypeEnum.ALL);
			sellerCoupon2.setCouponCode(sellerCouponCode2);
			sellerCoupon2.setCouponValue(sellerCouponValue2);
			groupVo2.setSellerCoupon(sellerCoupon2);
			// 卖家2
			int sellerId2 = Integer.valueOf(EnvSetup.getData("BuyerId"));
			groupVo2.setSellerId(sellerId2);
			List<OrderVo> sellerId2orders1 = new ArrayList<OrderVo>();
			OrderVo sellerId2order1 = new OrderVo();
			sellerId2order1.setAutoCancelOrderHours(new BigDecimal(1));
			sellerId2order1.setOrderType(OrderTypeEnum.Spot);
			sellerId2order1.setPaidFull(true);
			// 定义买手下订单列表
			List<OrderItemVo> sellerId2Items1 = new ArrayList<OrderItemVo>();
			// 订单1
			OrderItemVo sellerId2Item1 = new OrderItemVo();

			String catalogId2 = TestDataManager.getRandomUUID().toString();
			sellerId2Item1.setCatalogId(TestDataManager.getRandomUUID()
					.toString());
			// 商品数量
			int productNum2 = 1 + new Random().nextInt(5);
			sellerId2Item1.setProductNum(productNum2);
			sellerId2Item1.setProductName(productName);
			sellerId2Item1.setPriceType(PriceTypeEnum.VipPrice);
			sellerId2Item1.setProductId(productId);
			BigDecimal price2 = new BigDecimal(370);
			sellerId2Item1.setEarnestPrice(price2);
			sellerId2Item1.setProductPrice(price2);
			sellerId2Item1.setOriginalPrice(price2);
			sellerId2Item1.setSalesType(SalesTypeEnum.AlreadyInStock);
			sellerId2Item1.setLogisticsType(LogisticsTypeEnum.SailProtect);
			sellerId2Item1
					.setProductRefundChannel(ProductRefundChannelEnum.Official);
			sellerId2Items1.add(sellerId2Item1);
			sellerId2order1.setOrderItems(sellerId2Items1);
			sellerId2order1.setFreight(new BigDecimal("45"));
			sellerId2orders1.add(sellerId2order1);
			groupVo2.setOrders(sellerId2orders1);

			List<OrderGroupVo> orderGroupVos = new ArrayList<OrderGroupVo>();
			orderGroupVos.add(groupVo1);
			orderGroupVos.add(groupVo2);

			placeorderBean.setOrderGroups(orderGroupVos);
			placeorderCall.setData(placeorderBean);
			placeorderCall.callService();

			YmtCouponPrivateUserBoundWapper ymtCouponPrivate = new YmtCouponPrivateUserBoundWapper();
			List<YmtCouponPrivateUserBound> listCoupon = ymtCouponPrivate
					.selectBysCouponCode(couponCode);
			int ymtBeforeCount = listCoupon.get(0).getiCouponUsedCount();
			List<YmtCouponPrivateUserBound> listCoupon2 = ymtCouponPrivate
					.selectBysCouponCode(sellerCouponCode);
			int sellerBeforeCount = listCoupon2.get(0).getiCouponUsedCount();

			map.put("orderId", placeorderCall.getOrderIds());
			map.put("tradingId", placeorderCall.getTradingId());
			map.put("ymtCouponCode", couponCode);
			map.put("sellerCouponCode1", sellerCouponCode);
			map.put("sellerCouponCode2", sellerCouponCode2);
			map.put("ymtBeforeCount", ymtBeforeCount);
			map.put("sellerBeforeCount", sellerBeforeCount);
		} catch (Exception e) {
			Logger.fail(e);
		}
		return map;
	}

	// 创建一个订单，使用平台公共有优惠券，商家私有优惠券
	private Map placeOrder4() {
		Map map = new HashMap();
		try {
			PlaceOrderReq placeorderBean = new PlaceOrderReq();
			PlaceOrderCall placeorderCall = new PlaceOrderCall();
			int userId = Integer.valueOf(EnvSetup.getData("BuyUserId"));
			int sellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
			// 创建产品
			Logger.comment("前置数据准备");
			HashMap<String, Object> productInfo = ProductCallService
					.createProduct(sellerId, 3);
			Logger.comment("前置数据准备结束");
			String productId = (String) productInfo.get("productId");
			Logger.debug("productId:" + productId);
			String productName = (String) productInfo.get("productName");
			String pic = (String) productInfo.get("pic");
			BigDecimal price = (BigDecimal) (productInfo.get("price"));
			String catalogId = (String) productInfo.get("catalogId");
			YmatouCouponVo ymtCoupon = new YmatouCouponVo();
			// 平台优惠券
			BigDecimal couponValue = new BigDecimal(13);
			String couponCode = new OrderCallService()
					.receivePlatformShortCodeCoupon(couponValue);
			ymtCoupon.setApplianceType(YmatouCouponApplianceTypeEnum.ALL);

			ymtCoupon.setCouponCode(couponCode);
			ymtCoupon.setCouponValue(couponValue);
			placeorderBean.setAppId("AutoTest");
			placeorderBean.setYmatouCoupon(ymtCoupon);
			placeorderBean.setUserId(userId);
			placeorderBean.setRequestId(TestDataManager.getRandomUUID()
					.toString());
			placeorderBean.setTerminalSource(TerminalSourceEnum.IOS);
			placeorderBean.setAppTerminalSource(AppTerminalSourceEnum.Phone);
			OrderGroupVo groupVo1 = new OrderGroupVo();
			// 商家优惠券
			BigDecimal sellerCouponValue = new BigDecimal(15);
			String sellerCouponCode = new CouponCallService()
					.receiveCouponInfo(sellerId, userId, couponValue);
			SellerCouponVo sellerCoupon = new SellerCouponVo();
			sellerCoupon.setApplianceType(SellerCouponApplianceTypeEnum.ALL);
			sellerCoupon.setCouponCode(sellerCouponCode);
			sellerCoupon.setCouponValue(sellerCouponValue);
			groupVo1.setSellerCoupon(sellerCoupon);
			groupVo1.setSellerId(sellerId);

			List<OrderVo> orders = new ArrayList<OrderVo>();
			OrderVo ordervo1 = new OrderVo();
			ordervo1.setAutoCancelOrderHours(new BigDecimal(1));
			ordervo1.setOrderType(OrderTypeEnum.Spot);
			ordervo1.setPaidFull(true);

			List<OrderItemVo> items = new ArrayList<OrderItemVo>();
			OrderItemVo orderitem1 = new OrderItemVo();
			orderitem1.setProductNum(1);
			orderitem1.setProductName(productName);
			orderitem1.setPriceType(PriceTypeEnum.VipPrice);
			orderitem1.setProductId(productId);
			price = new BigDecimal(210);
			orderitem1.setEarnestPrice(price);
			orderitem1.setProductPrice(price);
			orderitem1.setOriginalPrice(price);
			orderitem1.setSalesType(SalesTypeEnum.AlreadyInStock);
			orderitem1.setLogisticsType(LogisticsTypeEnum.SailProtect);
			orderitem1
					.setProductRefundChannel(ProductRefundChannelEnum.Official);
			items.add(orderitem1);
			ordervo1.setOrderItems(items);
			ordervo1.setFreight(new BigDecimal("21"));

			orders.add(ordervo1);
			groupVo1.setOrders(orders);
			placeorderBean.setOrderGroups(Arrays.asList(groupVo1));
			placeorderCall.setData(false, placeorderBean);
			placeorderCall.callService();

			YmtCouponPrivateUserBoundWapper ymtCouponPrivate = new YmtCouponPrivateUserBoundWapper();
			// 查询公共优惠券使用情况
			List<Map> couponPublicUsed = new YmtCouponWapper()
					.selectYmtCouponPublicUsed(couponCode, userId);

			int ymtBeforeCount = (Integer) couponPublicUsed.get(0).get(
					"iCouponUsedCount");

			List<YmtCouponPrivateUserBound> listCoupon2 = ymtCouponPrivate
					.selectBysCouponCode(sellerCouponCode);
			int sellerBeforeCount = listCoupon2.get(0).getiCouponUsedCount();

			map.put("orderId", placeorderCall.getOrderIds().get(0));
			map.put("tradingId", placeorderCall.getTradingId());
			map.put("ymtCouponCode", couponCode);
			map.put("sellerCouponCode", sellerCouponCode);
			map.put("ymtBeforeCount", ymtBeforeCount);
			map.put("sellerBeforeCount", sellerBeforeCount);
		} catch (Exception e) {
			Logger.fail(e);
		}
		return map;
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_001() {
		Logger.start(true, "订单支付前,买家取消订单成功");
		try {
			// 创建订单
			Logger.comment("前置数据准备");
			PlaceOrderResp placeOrderResp = new OrderCallService()
					.createM2cOrder();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额
			Logger.comment("前置数据准备结束");

			String cancelReason = "自动化测试取消订单";
			cancelorderbean.setCancelReason(cancelReason);
			cancelorderbean.setCancelType(CancelOrderTypeEnum.BuyerCancelOrder);
			cancelorderbean.setOrderId(orderId);
			cancelorderbean.setUserId(userId);
			// 发送请求
			cancelordercall.setData(cancelorderbean);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");
			// 数据库验证
			DefaultWapper database = new DefaultWapper();
			Logger.verifyEquals(12, database.getTradingStatus(orderId),
					"验证订单交易状态");
			Logger.verifyEquals(
					1,
					database.selectOrderTradingStatusByOrderIdAndTradingStatus(
							orderId, 12).size(), "验证TradingStatus表中 增加一条订单操作记录");
			Logger.verifyEquals(1, database
					.selectOrderReasonByOrderIdAndUserId(orderId, userId)
					.size(), "验证Ymt_OrderReason表中增加一条订单取消原因记录");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_002() {
		Logger.start(true, "订单支付前,卖家取消订单成功");
		try {
			// 创建订单
			Logger.comment("前置数据准备");
			PlaceOrderResp placeOrderResp = new OrderCallService()
					.createM2cOrder();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额
			Logger.comment("前置数据准备结束");
			String cancelReason = "自动化测试取消订单";
			cancelorderbean.setCancelReason(cancelReason);
			cancelorderbean
					.setCancelType(CancelOrderTypeEnum.SellerCancelOrder);
			cancelorderbean.setOrderId(orderId);
			// 卖家取消的时候，为卖家ID
			cancelorderbean.setUserId(sellerId);
			// 发送请求
			cancelordercall.setData(cancelorderbean);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");
			// 数据库验证 这里不new DefaultWapper会出现数据库close的情况，待确认原因
			Logger.verifyEquals(13,
					new DefaultWapper().getTradingStatus(orderId), "验证订单交易状态");
			Logger.verifyEquals(
					1,
					new DefaultWapper()
							.selectOrderTradingStatusByOrderIdAndTradingStatus(
									orderId, 13).size(),
					"验证TradingStatus表中 增加一条订单操作记录");
			// Thread.sleep(30000);
			Logger.verifyEquals(1, new DefaultWapper()
					.selectOrderReasonByOrderIdAndUserId(orderId, sellerId)
					.size(), "验证Ymt_OrderReason表中增加一条订单取消原因记录");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_003() {
		Logger.start(true, "订单支付前,系统取消订单成功");
		try {
			// 创建订单
			Logger.comment("前置数据准备");
			PlaceOrderResp placeOrderResp = new OrderCallService()
					.createM2cOrder();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额
			Logger.comment("前置数据准备结束");
			String cancelReason = "自动化测试取消订单";
			cancelorderbean.setCancelReason(cancelReason);
			cancelorderbean
					.setCancelType(CancelOrderTypeEnum.SystemCancelOrder);
			cancelorderbean.setOrderId(orderId);
			cancelorderbean.setUserId(userId);
			// 修改订单自动取消时间为0
			new DefaultWapper().updateOrderAutoCancelOrderHoursByOrderId(0.00,
					orderId);
			// 发送请求
			cancelordercall.setData(cancelorderbean);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");
			// 数据库验证
			Logger.verifyEquals(18,
					new DefaultWapper().getTradingStatus(orderId), "验证订单交易状态");
			Logger.verifyEquals(
					1,
					new DefaultWapper()
							.selectOrderTradingStatusByOrderIdAndTradingStatus(
									orderId, 18).size(),
					"验证TradingStatus表中 增加一条订单操作记录");
			Logger.verifyEquals(1, new DefaultWapper()
					.selectOrderReasonByOrderIdAndUserId(orderId, userId)
					.size(), "验证Ymt_OrderReason表中增加一条订单取消原因记录");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_004() {
		Logger.start(true, "订单支付前,客服取消订单成功");
		try {
			// 创建订单
			Logger.comment("前置数据准备");
			PlaceOrderResp placeOrderResp = new OrderCallService()
					.createM2cOrder();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额
			Logger.comment("前置数据准备结束");
			String cancelReason = "自动化测试取消订单";
			cancelorderbean.setCancelReason(cancelReason);
			cancelorderbean
					.setCancelType(CancelOrderTypeEnum.CustomerCancelOrder);
			cancelorderbean.setOrderId(orderId);
			cancelorderbean.setUserId(userId);
			// 发送请求
			cancelordercall.setData(cancelorderbean);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");
			// 数据库验证
			Logger.verifyEquals(13,
					new DefaultWapper().getTradingStatus(orderId), "验证订单交易状态");
			Logger.verifyEquals(
					1,
					new DefaultWapper()
							.selectOrderTradingStatusByOrderIdAndTradingStatus(
									orderId, 13).size(),
					"验证TradingStatus表中 增加一条订单操作记录");
			Logger.verifyEquals(1, new DefaultWapper()
					.selectOrderReasonByOrderIdAndUserId(orderId, userId)
					.size(), "验证Ymt_OrderReason表中增加一条订单取消原因记录");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_005() {
		Logger.start(true, "订单卖家已接单,客服取消订单成功");
		try {
			// 创建订单
			OrderCallService orderService = new OrderCallService();
			Logger.comment("前置数据准备");
			PlaceOrderResp placeOrderResp = new OrderCallService()
					.createM2cOrder();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额
			Logger.comment("前置数据准备结束");
			// 买家付款
			orderService.orderPayRequest(userId, totalPrice, tradingId);
			// 接单
			orderService.acceptOrder(orderId, sellerId);
			/*
			 * // 商家发货 orderService.dispatched(orderId, sellerId); // 确认收货
			 * orderService.confirmReceive(userId, orderId);
			 */
			Logger.comment("前置数据准备结束");
			String cancelReason = "自动化测试客服取消订单";
			cancelorderbean.setCancelReason(cancelReason);
			cancelorderbean
					.setCancelType(CancelOrderTypeEnum.CustomerCancelOrder);
			cancelorderbean.setOrderId(orderId);
			cancelorderbean.setUserId(userId);
			// 发送请求
			cancelordercall.setData(cancelorderbean);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");
			// 数据库验证
			Logger.verifyEquals(13,
					new DefaultWapper().getTradingStatus(orderId), "验证订单交易状态");
			Logger.verifyEquals(
					1,
					new DefaultWapper()
							.selectOrderTradingStatusByOrderIdAndTradingStatus(
									orderId, 13).size(),
					"验证TradingStatus表中 增加一条订单操作记录");
			Logger.verifyEquals(1, new DefaultWapper()
					.selectOrderReasonByOrderIdAndUserId(orderId, userId)
					.size(), "验证Ymt_OrderReason表中增加一条订单取消原因记录");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_006() {
		Logger.start(true, "订单已支付商家未接单,风控取消订单成功");
		try {
			// 创建订单
			OrderCallService orderService = new OrderCallService();
			Logger.comment("前置数据准备");
			PlaceOrderResp placeOrderResp = new OrderCallService()
					.createM2cOrder();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额
			Logger.comment("前置数据准备结束");
			// 买家付款
			orderService.orderPayRequest(userId, totalPrice, tradingId);
			Logger.comment("前置数据准备结束");

			String cancelReason = "自动化测试风控取消订单";
			cancelorderbean.setCancelReason(cancelReason);
			cancelorderbean
					.setCancelType(CancelOrderTypeEnum.RiskControlCancelOrder);
			cancelorderbean.setOrderId(orderId);
			cancelorderbean.setUserId(userId); // 发送请求
			cancelordercall.setData(cancelorderbean);
			cancelordercall.callService();

			// 数据库验证
			Logger.verifyEquals(18,
					new DefaultWapper().getTradingStatus(orderId), "验证订单交易状态");
			Logger.verifyEquals(
					1,
					new DefaultWapper()
							.selectOrderTradingStatusByOrderIdAndTradingStatus(
									orderId, 18).size(),
					"验证TradingStatus表中 增加一条订单操作记录");
			Logger.verifyEquals(1, new DefaultWapper()
					.selectOrderReasonByOrderIdAndUserId(orderId, userId)
					.size(), "验证Ymt_OrderReason表中增加一条订单取消原因记录");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_007() {
		Logger.start(true, "订单已支付商家未接单,买家取消订单成功");
		try {
			// 创建订单
			OrderCallService orderService = new OrderCallService();
			Logger.comment("前置数据准备");
			PlaceOrderResp placeOrderResp = new OrderCallService()
					.createM2cOrder();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额
			Logger.comment("前置数据准备结束");
			// 支付订单
			new OrderCallService().orderPayRequest(userId, totalPrice,
					tradingId);
			Logger.comment("前置数据准备结束");
			String cancelReason = "自动化测试取消订单";
			cancelorderbean.setCancelReason(cancelReason);
			cancelorderbean.setCancelType(CancelOrderTypeEnum.BuyerCancelOrder);
			cancelorderbean.setOrderId(orderId);
			cancelorderbean.setUserId(userId);
			// 发送请求
			cancelordercall.setData(cancelorderbean);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");
			// 数据库验证
			DefaultWapper database = new DefaultWapper();
			Logger.verifyEquals(12, database.getTradingStatus(orderId),
					"验证订单交易状态");
			Logger.verifyEquals(
					1,
					database.selectOrderTradingStatusByOrderIdAndTradingStatus(
							orderId, 12).size(), "验证TradingStatus表中 增加一条订单操作记录");
			Logger.debug(database.selectOrderReasonByOrderIdAndUserId(orderId,
					userId).get(0));
			Logger.verifyEquals(1, database
					.selectOrderReasonByOrderIdAndUserId(orderId, userId)
					.size(), "验证Ymt_OrderReason表中增加一条订单取消原因记录");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_008() {
		Logger.start(true, "订单已支付商家未接单,卖家取消订单成功");
		try {
			// 创建订单
			OrderCallService orderService = new OrderCallService();
			Logger.comment("前置数据准备");
			PlaceOrderResp placeOrderResp = new OrderCallService()
					.createM2cOrder();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额
			Logger.comment("前置数据准备结束");
			// 支付订单
			new OrderCallService().orderPayRequest(userId, totalPrice,
					tradingId);
			Logger.comment("前置数据准备结束");
			String cancelReason = "自动化测试取消订单";
			cancelorderbean.setCancelReason(cancelReason);
			cancelorderbean
					.setCancelType(CancelOrderTypeEnum.SellerCancelOrder);
			cancelorderbean.setOrderId(orderId);
			cancelorderbean.setUserId(sellerId);
			// 发送请求
			cancelordercall.setData(cancelorderbean);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");
			// 数据库验证
			DefaultWapper database = new DefaultWapper();
			Logger.verifyEquals(13, database.getTradingStatus(orderId),
					"验证订单交易状态");
			Logger.verifyEquals(
					1,
					database.selectOrderTradingStatusByOrderIdAndTradingStatus(
							orderId, 13).size(), "验证TradingStatus表中 增加一条订单操作记录");
			Logger.verifyEquals(1, database
					.selectOrderReasonByOrderIdAndUserId(orderId, sellerId)
					.size(), "验证Ymt_OrderReason表中增加一条订单取消原因记录");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_009() {
		Logger.start(true, "订单已支付商家未接单,客服取消订单成功");
		try {
			// 创建订单
			OrderCallService orderService = new OrderCallService();
			Logger.comment("前置数据准备");
			PlaceOrderResp placeOrderResp = new OrderCallService()
					.createM2cOrder();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额
			Logger.comment("前置数据准备结束");
			// 支付订单
			new OrderCallService().orderPayRequest(userId, totalPrice,
					tradingId);
			Logger.comment("前置数据准备结束");
			String cancelReason = "自动化测试取消订单";
			cancelorderbean.setCancelReason(cancelReason);
			cancelorderbean
					.setCancelType(CancelOrderTypeEnum.CustomerCancelOrder);
			cancelorderbean.setOrderId(orderId);
			cancelorderbean.setUserId(sellerId);
			// 发送请求
			cancelordercall.setData(cancelorderbean);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");
			// 数据库验证
			DefaultWapper database = new DefaultWapper();
			Logger.verifyEquals(13, database.getTradingStatus(orderId),
					"验证订单交易状态");
			Logger.verifyEquals(
					1,
					database.selectOrderTradingStatusByOrderIdAndTradingStatus(
							orderId, 13).size(), "验证TradingStatus表中 增加一条订单操作记录");
			Logger.verifyEquals(1, database
					.selectOrderReasonByOrderIdAndUserId(orderId, sellerId)
					.size(), "验证Ymt_OrderReason表中增加一条订单取消原因记录");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_010() {
		Logger.start(true, "订单在退货退款中,取消订单失败");
		try {
			// 创建订单
			OrderCallService orderService = new OrderCallService();
			Logger.comment("前置数据准备");
			PlaceOrderResp placeOrderResp = new OrderCallService()
					.createM2cOrder();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额
			Logger.comment("前置数据准备结束");
			// 买家付款
			orderService.orderPayRequest(userId, totalPrice, tradingId);
			// 退货退款同步
			orderService.applySalesRefundRequestInJava(orderId);
			Logger.comment("前置数据准备结束");
			String cancelReason = "自动化测试取消订单";
			cancelorderbean.setCancelReason(cancelReason);
			cancelorderbean.setCancelType(CancelOrderTypeEnum.BuyerCancelOrder);
			cancelorderbean.setOrderId(orderId);
			cancelorderbean.setUserId(userId);
			// 发送请求
			cancelordercall.setData(cancelorderbean);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.FAILED201, cancelordercall.getCode(),
					"验证Code");
			Logger.verifyIsContains("哈尼，" + orderId + "此单有退货/退款，请先去处理~",
					cancelordercall.getMsg(), "验证Msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_CancelOrder_011() {
		Logger.start(false, "订单支付前,重复取消订单成功");
		try {
			// 创建订单
			OrderCallService orderService = new OrderCallService();
			Logger.comment("前置数据准备");
			PlaceOrderResp placeOrderResp = new OrderCallService()
					.createM2cOrder();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额
			Logger.comment("前置数据准备结束");
			String cancelReason = "自动化测试取消订单";
			cancelorderbean.setCancelReason(cancelReason);
			cancelorderbean.setCancelType(CancelOrderTypeEnum.BuyerCancelOrder);
			cancelorderbean.setOrderId(orderId);
			cancelorderbean.setUserId(userId);
			// 发送请求
			cancelordercall.setData(cancelorderbean);
			cancelordercall.callService();
			// cancelordercall.setData(cancelorderbean);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.FAILED201, cancelordercall.getCode(),
					"验证Code");
			Logger.verifyEquals(orderId + "此订单已取消~", cancelordercall.getMsg(),
					"验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_CancelOrder_012() {
		Logger.start(false, "订单不存在");
		try {
			String cancelReason = "自动化测试取消订单";
			cancelorderbean.setCancelReason(cancelReason);
			cancelorderbean.setCancelType(CancelOrderTypeEnum.BuyerCancelOrder);
			int orderId = 11;
			cancelorderbean.setOrderId(orderId);
			int userId = 1113;
			cancelorderbean.setUserId(userId);
			// 发送请求
			cancelordercall.setData(cancelorderbean);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.FAILED201, cancelordercall.getCode(),
					"验证Code");
			Logger.verifyIsContains(ECode.FAILED201_MSG_11,
					cancelordercall.getMsg(), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_CancelOrder_013() {
		Logger.start(true, "商家已接单,买家取消订单失败");
		try {
			// 创建订单
			OrderCallService orderService = new OrderCallService();
			Logger.comment("前置数据准备");
			PlaceOrderResp placeOrderResp = new OrderCallService()
					.createM2cOrder();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额
			Logger.comment("前置数据准备结束");
			// 支付订单
			orderService.orderPayRequest(userId, totalPrice, tradingId);
			// 接单
			orderService.acceptOrder(orderId, sellerId);
			Logger.comment("前置数据准备结束");
			String cancelReason = "自动化测试取消订单";
			cancelorderbean.setCancelReason(cancelReason);
			cancelorderbean.setCancelType(CancelOrderTypeEnum.BuyerCancelOrder);
			cancelorderbean.setOrderId(orderId);
			cancelorderbean.setUserId(userId);
			// 发送请求
			cancelordercall.setData(cancelorderbean);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.FAILED201, cancelordercall.getCode(),
					"验证Code");
			Logger.verifyIsContains("哈尼，你的订单" + orderId
					+ "，买手刚刚接单了，只能走退货退款流程了哦~", cancelordercall.getMsg(),
					"验证Msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_014() {
		Logger.start(true, "订单已收货,,客服取消订单失败");
		try {
			// 创建订单
			OrderCallService orderService = new OrderCallService();
			Logger.comment("前置数据准备");
			PlaceOrderResp placeOrderResp = new OrderCallService()
					.createM2cOrder();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额
			Logger.comment("前置数据准备结束");
			// 买家付款
			orderService.orderPayRequest(userId, totalPrice, tradingId);
			// 接单
			orderService.acceptOrder(orderId, sellerId);
			// 商家发货
			orderService.dispatched(orderId, sellerId);
			// 确认收货
			orderService.confirmReceive(userId, orderId);
			Logger.comment("前置数据准备结束");
			String cancelReason = "自动化测试取消订单";
			cancelorderbean.setCancelReason(cancelReason);
			cancelorderbean
					.setCancelType(CancelOrderTypeEnum.CustomerCancelOrder);
			cancelorderbean.setOrderId(orderId);
			cancelorderbean.setUserId(userId);
			// 发送请求
			cancelordercall.setData(cancelorderbean);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.FAILED201, cancelordercall.getCode(),
					"验证Code");
			Logger.verifyEquals("客服取消订单" + orderId + "状态不匹配",
					cancelordercall.getMsg(), "验证Msg");
			// 数据库验证
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_CancelOrder_015() {
		Logger.start(false, "买家用户不是订单的所有者");
		try {
			// 创建订单
			OrderCallService orderService = new OrderCallService();
			Logger.comment("前置数据准备");
			PlaceOrderResp placeOrderResp = new OrderCallService()
					.createM2cOrder();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额
			Logger.comment("前置数据准备结束");
			String cancelReason = "自动化测试取消订单";
			Logger.comment("前置数据准备结束");
			cancelorderbean.setCancelReason(cancelReason);
			cancelorderbean.setCancelType(CancelOrderTypeEnum.BuyerCancelOrder);
			cancelorderbean.setOrderId(orderId);
			cancelorderbean.setUserId(userId + 1);
			// 发送请求
			cancelordercall.setData(cancelorderbean);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.FAILED201, cancelordercall.getCode(),
					"验证Code");
			Logger.verifyEquals("用户" + cancelorderbean.getUserId() + "不是订单"
					+ orderId + "的所有者", cancelordercall.getMsg(), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_016() {
		Logger.start(true, "订单已支付商家未接单,使用平台,商家优惠券风控取消订单成功,不退优惠券");
		try {
			int userId = Integer.valueOf(EnvSetup.getData("BuyUserId"));
			int sellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
			// 创建订单
			Logger.comment("前置数据准备");
			OrderCallService orderService = new OrderCallService();
			Map map = placeOrder();
			int orderId = (Integer) map.get("orderId");
			int tradingId = (Integer) map.get("tradingId");
			int ymtBeforeCount = (Integer) map.get("ymtBeforeCount");
			int sellerBeforeCount = (Integer) map.get("sellerBeforeCount");
			String ymtCouponCode = (String) map.get("ymtCouponCode");
			String sellerCouponCode = (String) map.get("sellerCouponCode");

			BigDecimal totalPrice = orderService
					.getNeedPrePayAmountOfCash(orderId);
			// 买家付款
			orderService.orderPayRequest(userId, totalPrice, tradingId);
			Logger.comment("前置数据准备结束");
			String cancelReason = "自动化测试风控取消订单";
			cancelorderbean.setCancelReason(cancelReason);
			cancelorderbean
					.setCancelType(CancelOrderTypeEnum.RiskControlCancelOrder);
			cancelorderbean.setOrderId(orderId);
			cancelorderbean.setUserId(userId); // 发送请求
			cancelordercall.setData(cancelorderbean);
			cancelordercall.callService();

			// 数据库验证
			YmtCouponPrivateUserBoundWapper ymtCoupon = new YmtCouponPrivateUserBoundWapper();
			List<YmtCouponPrivateUserBound> listCoupon1 = ymtCoupon
					.selectBysCouponCode(ymtCouponCode);
			List<YmtCouponPrivateUserBound> listCoupon2 = ymtCoupon
					.selectBysCouponCode(sellerCouponCode);
			// 查询交易，退款同步表
			DefaultWapper database = new DefaultWapper();
			List<Map> settlementList = database
					.selectYmtSettlementInvoice(orderId);
			// 订单主表
			List<Map> ymtOrders = database.selectOrderByOderId(orderId);
			// 资金流水表
			List<YmtAccountEntry> ymtActList = new AccountDefaultWapper()
					.selectAccountEntryByUserId(userId);
			Logger.verifyEquals(18,
					new DefaultWapper().getTradingStatus(orderId), "验证订单交易状态");
			Logger.verifyEquals(
					1,
					new DefaultWapper()
							.selectOrderTradingStatusByOrderIdAndTradingStatus(
									orderId, 18).size(),
					"验证TradingStatus表中 增加一条订单操作记录");
			Logger.verifyEquals(1, new DefaultWapper()
					.selectOrderReasonByOrderIdAndUserId(orderId, userId)
					.size(), "验证Ymt_OrderReason表中增加一条订单取消原因记录");
			Logger.verifyEquals(ymtBeforeCount, listCoupon1.get(0)
					.getiCouponUsedCount(), "验证ymt平台优惠券不退回");
			Logger.verifyEquals(sellerBeforeCount, listCoupon2.get(0)
					.getiCouponUsedCount(), "验证商家优惠券不退回");

			Logger.verifyEquals(totalPrice, (BigDecimal) settlementList.get(0)
					.get("CashAmount"), "验证退款金额是否等于付款金额");
			Logger.verifyEquals(1, settlementList.get(0).get("SettlementUser"),
					"验证SettlementUser 为1");
			Logger.verifyEquals(1, settlementList.get(0)
					.get("SettlementStatus"), "验证SettlementStatus 为1");
			Logger.verifyEquals(3, settlementList.get(0).get("BusinessType"),
					"验证BusinessType 为3");
			Logger.verifyEquals(
					(BigDecimal) ymtOrders.get(0).get("fYmtCouponAmount"),
					(BigDecimal) settlementList.get(0).get("CouponAmount"),
					"验证退款结算单退回的平台CouponAmount");
			Logger.verifyEquals(totalPrice, ymtActList.get(0).getAmount(),
					"验证用户账户流水表取消订单退回用户支付的余额");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_017() {
		Logger.start(true, "接单前取消,退优惠券");
		try {
			int userId = Integer.valueOf(EnvSetup.getData("BuyUserId"));
			int sellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
			// 创建订单
			Logger.comment("前置数据准备");
			OrderCallService orderService = new OrderCallService();
			Map map = placeOrder();
			int orderId = (Integer) map.get("orderId");
			int tradingId = (Integer) map.get("tradingId");
			int ymtBeforeCount = (Integer) map.get("ymtBeforeCount");
			int sellerBeforeCount = (Integer) map.get("sellerBeforeCount");
			String ymtCouponCode = (String) map.get("ymtCouponCode");
			String sellerCouponCode = (String) map.get("sellerCouponCode");

			BigDecimal totalPrice = orderService
					.getNeedPrePayAmountOfCash(orderId);
			// 买家付款
			orderService.orderPayRequest(userId, totalPrice, tradingId);
			// 接单
			// orderService.acceptOrder(orderId, sellerId);
			Logger.comment("前置数据准备结束");
			String cancelReason = "自动化测试取消订单";
			cancelorderbean.setCancelReason(cancelReason);
			cancelorderbean.setCancelType(CancelOrderTypeEnum.BuyerCancelOrder);
			cancelorderbean.setOrderId(orderId);
			cancelorderbean.setUserId(userId);
			// 发送请求
			cancelordercall.setData(cancelorderbean);
			cancelordercall.callService();
			// 数据库验证
			YmtCouponPrivateUserBoundWapper ymtCoupon = new YmtCouponPrivateUserBoundWapper();
			List<YmtCouponPrivateUserBound> listCoupon1 = ymtCoupon
					.selectBysCouponCode(ymtCouponCode);
			List<YmtCouponPrivateUserBound> listCoupon2 = ymtCoupon
					.selectBysCouponCode(sellerCouponCode);
			// 查询交易，退款同步表
			DefaultWapper database = new DefaultWapper();
			List<Map> settlementList = database
					.selectYmtSettlementInvoice(orderId);
			// 订单主表
			List<Map> ymtOrders = database.selectOrderByOderId(orderId);
			// 资金流水表
			List<YmtAccountEntry> ymtActList = new AccountDefaultWapper()
					.selectAccountEntryByUserId(userId);

			Logger.verifyEquals(12,
					new DefaultWapper().getTradingStatus(orderId), "验证订单交易状态");
			Logger.verifyEquals(
					1,
					new DefaultWapper()
							.selectOrderTradingStatusByOrderIdAndTradingStatus(
									orderId, 12).size(),
					"验证TradingStatus表中 增加一条订单操作记录");
			Logger.verifyEquals(1, new DefaultWapper()
					.selectOrderReasonByOrderIdAndUserId(orderId, userId)
					.size(), "验证Ymt_OrderReason表中增加一条订单取消原因记录");
			Logger.verifyEquals(ymtBeforeCount + 1, listCoupon1.get(0)
					.getiCouponUsedCount(), "验证ymt平台优惠券退回");
			Logger.verifyEquals(sellerBeforeCount + 1, listCoupon2.get(0)
					.getiCouponUsedCount(), "验证商家优惠券退回");

			Logger.verifyEquals(totalPrice, (BigDecimal) settlementList.get(0)
					.get("CashAmount"), "验证退款金额是否等于付款金额");
			Logger.verifyEquals(1, settlementList.get(0).get("SettlementUser"),
					"验证SettlementUser 为1");
			Logger.verifyEquals(1, settlementList.get(0)
					.get("SettlementStatus"), "验证SettlementStatus 为1");
			Logger.verifyEquals(3, settlementList.get(0).get("BusinessType"),
					"验证BusinessType 为3");
			Logger.verifyEquals(
					(BigDecimal) ymtOrders.get(0).get("fYmtCouponAmount"),
					(BigDecimal) settlementList.get(0).get("CouponAmount"),
					"验证退款结算单退回的平台CouponAmount");
			Logger.verifyEquals(totalPrice, ymtActList.get(0).getAmount(),
					"验证用户账户流水表取消订单退回用户支付的余额");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_018() {
		Logger.start(true, "使用平台,商家优惠券.接单后客服取消订单,不退优惠券");
		try {
			int userId = Integer.valueOf(EnvSetup.getData("BuyUserId"));
			int sellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
			// 创建订单
			Logger.comment("前置数据准备");
			OrderCallService orderService = new OrderCallService();
			Map map = placeOrder();
			int orderId = (Integer) map.get("orderId");
			int tradingId = (Integer) map.get("tradingId");
			int ymtBeforeCount = (Integer) map.get("ymtBeforeCount");
			int sellerBeforeCount = (Integer) map.get("sellerBeforeCount");
			String ymtCouponCode = (String) map.get("ymtCouponCode");
			String sellerCouponCode = (String) map.get("sellerCouponCode");
			BigDecimal totalPrice = orderService
					.getNeedPrePayAmountOfCash(orderId);
			// 买家付款
			orderService.orderPayRequest(userId, totalPrice, tradingId);
			// 接单
			orderService.acceptOrder(orderId, sellerId);
			Logger.comment("前置数据准备结束");
			String cancelReason = "自动化测试取消订单";
			cancelorderbean.setCancelReason(cancelReason);
			cancelorderbean
					.setCancelType(CancelOrderTypeEnum.CustomerCancelOrder);
			cancelorderbean.setOrderId(orderId);
			cancelorderbean.setUserId(userId);
			// 发送请求
			cancelordercall.setData(false, cancelorderbean);
			cancelordercall.callService();
			// 数据库验证
			YmtCouponPrivateUserBoundWapper ymtCoupon = new YmtCouponPrivateUserBoundWapper();
			List<YmtCouponPrivateUserBound> listCoupon1 = ymtCoupon
					.selectBysCouponCode(ymtCouponCode);
			List<YmtCouponPrivateUserBound> listCoupon2 = ymtCoupon
					.selectBysCouponCode(sellerCouponCode);
			// 查询交易，退款同步表
			DefaultWapper database = new DefaultWapper();
			List<Map> settlementList = database
					.selectYmtSettlementInvoice(orderId);
			// 订单主表
			List<Map> ymtOrders = database.selectOrderByOderId(orderId);
			// 资金流水表
			List<YmtAccountEntry> ymtActList = new AccountDefaultWapper()
					.selectAccountEntryByUserId(userId);

			Logger.verifyEquals(13,
					new DefaultWapper().getTradingStatus(orderId), "验证订单交易状态");
			Logger.verifyEquals(
					1,
					new DefaultWapper()
							.selectOrderTradingStatusByOrderIdAndTradingStatus(
									orderId, 13).size(),
					"验证TradingStatus表中 增加一条订单操作记录");
			Logger.verifyEquals(1, new DefaultWapper()
					.selectOrderReasonByOrderIdAndUserId(orderId, userId)
					.size(), "验证Ymt_OrderReason表中增加一条订单取消原因记录");
			Logger.verifyEquals(ymtBeforeCount, listCoupon1.get(0)
					.getiCouponUsedCount(), "验证ymt平台优惠券不退回");
			Logger.verifyEquals(sellerBeforeCount, listCoupon2.get(0)
					.getiCouponUsedCount(), "验证商家优惠券不退回");

			Logger.verifyEquals(totalPrice, (BigDecimal) settlementList.get(0)
					.get("CashAmount"), "验证退款金额是否等于付款金额");
			Logger.verifyEquals(1, settlementList.get(0).get("SettlementUser"),
					"验证SettlementUser 为1");
			Logger.verifyEquals(1, settlementList.get(0)
					.get("SettlementStatus"), "验证SettlementStatus 为1");
			Logger.verifyEquals(3, settlementList.get(0).get("BusinessType"),
					"验证BusinessType 为3");
			Logger.verifyEquals(
					(BigDecimal) ymtOrders.get(0).get("fYmtCouponAmount"),
					(BigDecimal) settlementList.get(0).get("CouponAmount"),
					"验证退款结算单退回的平台CouponAmount");
			Logger.verifyEquals(totalPrice, ymtActList.get(0).getAmount(),
					"验证用户账户流水表取消订单退回用户支付的余额");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_019() {
		Logger.start(true, "未付款状态,同一主单号下面订单全部取消,平台优惠券退回");
		try {
			int userId = Integer.valueOf(EnvSetup.getData("BuyUserId"));
			int sellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
			// 创建订单
			Logger.comment("前置数据准备");
			OrderCallService orderService = new OrderCallService();
			Map map = placeOrder2();
			JSONArray orderIds = (JSONArray) map.get("orderId");
			int tradingId = (Integer) map.get("tradingId");
			int ymtBeforeCount = (Integer) map.get("ymtBeforeCount");
			int sellerBeforeCount = (Integer) map.get("sellerBeforeCount");
			String ymtCouponCode = (String) map.get("ymtCouponCode");
			String sellerCouponCode = (String) map.get("sellerCouponCode");
			int orderId1 = orderIds.getInt(0);
			int orderId2 = orderIds.getInt(1);

			BigDecimal totalPrice = orderService
					.getNeedPrePayAmountOfCash(orderId1);
			// 买家付款
			// orderService.orderPayRequest(userId, totalPrice, tradingId);
			// 接单
			// orderService.acceptOrder(orderId, sellerId);
			Logger.comment("前置数据准备结束");
			String cancelReason = "自动化测试取消订单";
			cancelorderbean.setCancelReason(cancelReason);
			cancelorderbean.setCancelType(CancelOrderTypeEnum.BuyerCancelOrder);
			cancelorderbean.setOrderId(orderId1);
			cancelorderbean.setUserId(userId);
			// 发送请求
			Logger.comment("退第1个订单:" + orderId1);
			cancelordercall.setData(false, cancelorderbean);
			cancelordercall.callService();
			// 数据库验证
			YmtCouponPrivateUserBoundWapper ymtCoupon = new YmtCouponPrivateUserBoundWapper();
			List<YmtCouponPrivateUserBound> listCoupon1 = new ArrayList<YmtCouponPrivateUserBound>();
			List<YmtCouponPrivateUserBound> listCoupon2 = new ArrayList<YmtCouponPrivateUserBound>();
			listCoupon1 = ymtCoupon.selectBysCouponCode(ymtCouponCode);
			listCoupon2 = ymtCoupon.selectBysCouponCode(sellerCouponCode);
			// 查询交易，退款同步表
			DefaultWapper database = new DefaultWapper();
			List<Map> settlementList = database
					.selectYmtSettlementInvoice(orderId1);
			// 订单主表
			List<Map> ymtOrders = database.selectOrderByOderId(orderId1);

			Logger.verifyEquals(12,
					new DefaultWapper().getTradingStatus(orderId1), "验证订单交易状态");
			Logger.verifyEquals(
					1,
					new DefaultWapper()
							.selectOrderTradingStatusByOrderIdAndTradingStatus(
									orderId1, 12).size(),
					"验证TradingStatus表中 增加一条订单操作记录");
			Logger.verifyEquals(1, new DefaultWapper()
					.selectOrderReasonByOrderIdAndUserId(orderId1, userId)
					.size(), "验证Ymt_OrderReason表中增加一条订单取消原因记录");
			Logger.verifyEquals(ymtBeforeCount, listCoupon1.get(0)
					.getiCouponUsedCount(), "验证同一主单下,订单没有全部取消,ymt平台优惠券不退回");
			Logger.verifyEquals(sellerBeforeCount, listCoupon2.get(0)
					.getiCouponUsedCount(), "验证同一主单下,订单没有全部取消,商家优惠券不退回");

			cancelorderbean.setOrderId(orderId2);
			// 发送请求
			Logger.comment("退第2个订单:" + orderId2);
			cancelordercall.setData(false, cancelorderbean);
			cancelordercall.callService();

			listCoupon1 = ymtCoupon.selectBysCouponCode(ymtCouponCode);
			listCoupon2 = ymtCoupon.selectBysCouponCode(sellerCouponCode);
			Logger.verifyEquals(12,
					new DefaultWapper().getTradingStatus(orderId2), "验证订单交易状态");
			Logger.verifyEquals(
					1,
					new DefaultWapper()
							.selectOrderTradingStatusByOrderIdAndTradingStatus(
									orderId2, 12).size(),
					"验证TradingStatus表中 增加一条订单操作记录");
			Logger.verifyEquals(1, new DefaultWapper()
					.selectOrderReasonByOrderIdAndUserId(orderId2, userId)
					.size(), "验证Ymt_OrderReason表中增加一条订单取消原因记录");
			Logger.verifyEquals(ymtBeforeCount + 1, listCoupon1.get(0)
					.getiCouponUsedCount(), "验证同一主单下,订单全部取消。ymt平台优惠券退回");
			Logger.verifyEquals(sellerBeforeCount + 1, listCoupon2.get(0)
					.getiCouponUsedCount(), "验证同一主单下,订单全部取消,商家优惠券退回");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_020() {
		Logger.start(true, "已付款状态:同一主单号下面只有1个商家的订单,订单全部取消才退回平台优惠券");
		try {
			int userId = Integer.valueOf(EnvSetup.getData("BuyUserId"));
			int sellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
			// 创建订单
			Logger.comment("前置数据准备");
			OrderCallService orderService = new OrderCallService();
			Map map = placeOrder2();
			JSONArray orderIds = (JSONArray) map.get("orderId");
			int tradingId = (Integer) map.get("tradingId");
			int ymtBeforeCount = (Integer) map.get("ymtBeforeCount");
			int sellerBeforeCount = (Integer) map.get("sellerBeforeCount");
			String ymtCouponCode = (String) map.get("ymtCouponCode");
			String sellerCouponCode = (String) map.get("sellerCouponCode");
			int orderId1 = orderIds.getInt(0);
			int orderId2 = orderIds.getInt(1);

			BigDecimal totalPrice1 = orderService
					.getNeedPrePayAmountOfCash(orderId1);
			BigDecimal totalPrice2 = orderService
					.getNeedPrePayAmountOfCash(orderId2);

			// 买家付款
			orderService.orderPayRequest(userId, totalPrice1.add(totalPrice2),
					tradingId);
			// 接单
			// orderService.acceptOrder(orderId, sellerId);
			Logger.comment("前置数据准备结束");
			String cancelReason = "自动化测试取消订单";
			cancelorderbean.setCancelReason(cancelReason);
			cancelorderbean.setCancelType(CancelOrderTypeEnum.BuyerCancelOrder);
			cancelorderbean.setOrderId(orderId1);
			cancelorderbean.setUserId(userId);
			// 发送请求
			Logger.comment("退第1个订单:" + orderId2);
			cancelordercall.setData(false, cancelorderbean);
			cancelordercall.callService();
			Thread.sleep(3000);
			// 查询交易，退款同步表
			DefaultWapper database = new DefaultWapper();
			List<Map> settlementList = new ArrayList<Map>();
			settlementList = database.selectYmtSettlementInvoice(orderId1);
			// 订单主表
			List<Map> ymtOrders = new ArrayList<Map>();
			ymtOrders = database.selectOrderByOderId(orderId1);
			// 资金流水表
			List<YmtAccountEntry> ymtActList = new ArrayList<YmtAccountEntry>();
			ymtActList = new AccountDefaultWapper()
					.selectAccountEntryByUserId(userId);
			// 数据库验证
			YmtCouponPrivateUserBoundWapper ymtCoupon = new YmtCouponPrivateUserBoundWapper();
			List<YmtCouponPrivateUserBound> listCoupon1 = new ArrayList<YmtCouponPrivateUserBound>();
			List<YmtCouponPrivateUserBound> listCoupon2 = new ArrayList<YmtCouponPrivateUserBound>();
			listCoupon1 = ymtCoupon.selectBysCouponCode(ymtCouponCode);
			listCoupon2 = ymtCoupon.selectBysCouponCode(sellerCouponCode);
			Logger.verifyEquals(12,
					new DefaultWapper().getTradingStatus(orderId1), "验证订单交易状态");
			Logger.verifyEquals(
					1,
					new DefaultWapper()
							.selectOrderTradingStatusByOrderIdAndTradingStatus(
									orderId1, 12).size(),
					"验证TradingStatus表中 增加一条订单操作记录");
			Logger.verifyEquals(1, new DefaultWapper()
					.selectOrderReasonByOrderIdAndUserId(orderId1, userId)
					.size(), "验证Ymt_OrderReason表中增加一条订单取消原因记录");
			Logger.verifyEquals(ymtBeforeCount, listCoupon1.get(0)
					.getiCouponUsedCount(), "验证同一主单下,订单没有全部取消,ymt平台优惠券不退回");
			Logger.verifyEquals(sellerBeforeCount, listCoupon2.get(0)
					.getiCouponUsedCount(), "验证同一主单下,订单没有全部取消,商家优惠券不退回");

			Logger.verifyEquals(totalPrice1, (BigDecimal) settlementList.get(0)
					.get("CashAmount"), "验证退款金额是否等于付款金额");
			Logger.verifyEquals(1, settlementList.get(0).get("SettlementUser"),
					"验证SettlementUser 为1");
			Logger.verifyEquals(1, settlementList.get(0)
					.get("SettlementStatus"), "验证SettlementStatus 为1");
			Logger.verifyEquals(3, settlementList.get(0).get("BusinessType"),
					"验证BusinessType 为3");
			Logger.verifyEquals(
					(BigDecimal) ymtOrders.get(0).get("fYmtCouponAmount"),
					(BigDecimal) settlementList.get(0).get("CouponAmount"),
					"验证退款结算单退回的平台CouponAmount");
			Logger.verifyEquals(totalPrice1, ymtActList.get(0).getAmount(),
					"验证用户账户流水表取消订单退回用户支付的余额");

			cancelorderbean.setOrderId(orderId2);
			// 发送请求
			Logger.comment("退第2个订单:" + orderId2);
			cancelordercall.setData(false, cancelorderbean);
			cancelordercall.callService();
			Thread.sleep(3000);
			settlementList = database.selectYmtSettlementInvoice(orderId2);
			// 订单主表
			ymtOrders = database.selectOrderByOderId(orderId2);
			// 资金流水表
			ymtActList = new AccountDefaultWapper()
					.selectAccountEntryByUserId(userId);
			listCoupon1 = ymtCoupon.selectBysCouponCode(ymtCouponCode);
			listCoupon2 = ymtCoupon.selectBysCouponCode(sellerCouponCode);
			Logger.verifyEquals(12,
					new DefaultWapper().getTradingStatus(orderId2), "验证订单交易状态");
			Logger.verifyEquals(
					1,
					new DefaultWapper()
							.selectOrderTradingStatusByOrderIdAndTradingStatus(
									orderId2, 12).size(),
					"验证TradingStatus表中 增加一条订单操作记录");
			Logger.verifyEquals(1, new DefaultWapper()
					.selectOrderReasonByOrderIdAndUserId(orderId2, userId)
					.size(), "验证Ymt_OrderReason表中增加一条订单取消原因记录");
			Logger.verifyEquals(ymtBeforeCount + 1, listCoupon1.get(0)
					.getiCouponUsedCount(), "验证同一主单下,订单全部取消。ymt平台优惠券退回");
			Logger.verifyEquals(sellerBeforeCount + 1, listCoupon2.get(0)
					.getiCouponUsedCount(), "验证同一主单下,订单全部取消,商家优惠券退回");

			Logger.verifyEquals(totalPrice2, (BigDecimal) settlementList.get(0)
					.get("CashAmount"), "验证退款金额是否等于付款金额");
			Logger.verifyEquals(1, settlementList.get(0).get("SettlementUser"),
					"验证SettlementUser 为1");
			Logger.verifyEquals(1, settlementList.get(0)
					.get("SettlementStatus"), "验证SettlementStatus 为1");
			Logger.verifyEquals(3, settlementList.get(0).get("BusinessType"),
					"验证BusinessType 为3");
			Logger.verifyEquals(
					(BigDecimal) ymtOrders.get(0).get("fYmtCouponAmount"),
					(BigDecimal) settlementList.get(0).get("CouponAmount"),
					"验证退款结算单退回的平台CouponAmount");
			Logger.verifyEquals(totalPrice2, ymtActList.get(0).getAmount(),
					"验证用户账户流水表取消订单退回用户支付的余额");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_021() {
		Logger.start(true, "已付款状态:同一主单号下面有多个商家的订单,即使订单全部取消,退回商家券,不退回平台优惠券");
		try {
			int userId = Integer.valueOf(EnvSetup.getData("BuyUserId"));
			int sellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
			// 创建订单
			Logger.comment("前置数据准备");
			OrderCallService orderService = new OrderCallService();
			Map map = placeOrder3();
			JSONArray orderIds = (JSONArray) map.get("orderId");
			int tradingId = (Integer) map.get("tradingId");
			int ymtBeforeCount = (Integer) map.get("ymtBeforeCount");
			int sellerBeforeCount = (Integer) map.get("sellerBeforeCount");
			String ymtCouponCode = (String) map.get("ymtCouponCode");
			String sellerCouponCode1 = (String) map.get("sellerCouponCode1");
			String sellerCouponCode2 = (String) map.get("sellerCouponCode2");

			int orderId1 = orderIds.getInt(0);
			int orderId2 = orderIds.getInt(1);
			int orderId3 = orderIds.getInt(2);

			BigDecimal totalPrice1 = orderService
					.getNeedPrePayAmountOfCash(orderId1);
			BigDecimal totalPrice2 = orderService
					.getNeedPrePayAmountOfCash(orderId2);
			BigDecimal totalPrice3 = orderService
					.getNeedPrePayAmountOfCash(orderId3);
			// 买家付款
			orderService.orderPayRequest(userId, totalPrice1.add(totalPrice2)
					.add(totalPrice3), tradingId);
			// 接单
			// orderService.acceptOrder(orderId, sellerId);
			Logger.comment("前置数据准备结束");
			String cancelReason = "自动化测试取消订单";
			cancelorderbean.setCancelReason(cancelReason);
			cancelorderbean.setCancelType(CancelOrderTypeEnum.BuyerCancelOrder);
			cancelorderbean.setOrderId(orderId1);
			cancelorderbean.setUserId(userId);
			// 发送请求
			Logger.comment("退第1个订单:" + orderId1);
			cancelordercall.setData(false, cancelorderbean);
			cancelordercall.callService();
			Thread.sleep(5000);
			// 查询交易，退款同步表
			DefaultWapper database = new DefaultWapper();
			List<Map> settlementList = new ArrayList<Map>();
			settlementList = database.selectYmtSettlementInvoice(orderId1);
			// 订单主表
			List<Map> ymtOrders = new ArrayList<Map>();
			ymtOrders = database.selectOrderByOderId(orderId1);
			// 资金流水表
			List<YmtAccountEntry> ymtActList = new ArrayList<YmtAccountEntry>();
			ymtActList = new AccountDefaultWapper()
					.selectAccountEntryByUserId(userId);
			// 数据库验证
			YmtCouponPrivateUserBoundWapper ymtCoupon = new YmtCouponPrivateUserBoundWapper();
			List<YmtCouponPrivateUserBound> listCoupon1 = new ArrayList<YmtCouponPrivateUserBound>();
			List<YmtCouponPrivateUserBound> listCoupon2 = new ArrayList<YmtCouponPrivateUserBound>();
			listCoupon1 = ymtCoupon.selectBysCouponCode(ymtCouponCode);
			listCoupon2 = ymtCoupon.selectBysCouponCode(sellerCouponCode1);
			Logger.verifyEquals(12,
					new DefaultWapper().getTradingStatus(orderId1), "验证订单交易状态");
			Logger.verifyEquals(
					1,
					new DefaultWapper()
							.selectOrderTradingStatusByOrderIdAndTradingStatus(
									orderId1, 12).size(),
					"验证TradingStatus表中 增加一条订单操作记录");
			Logger.verifyEquals(1, new DefaultWapper()
					.selectOrderReasonByOrderIdAndUserId(orderId1, userId)
					.size(), "验证Ymt_OrderReason表中增加一条订单取消原因记录");
			Logger.verifyEquals(ymtBeforeCount, listCoupon1.get(0)
					.getiCouponUsedCount(), "验证同一主单下,订单没有全部取消,ymt平台优惠券不退回");
			Logger.verifyEquals(sellerBeforeCount, listCoupon2.get(0)
					.getiCouponUsedCount(), "验证同一主单下,订单没有全部取消,商家优惠券不退回");

			Logger.verifyEquals(totalPrice1, (BigDecimal) settlementList.get(0)
					.get("CashAmount"), "验证退款金额是否等于付款金额");
			Logger.verifyEquals(1, settlementList.get(0).get("SettlementUser"),
					"验证SettlementUser 为1");
			Logger.verifyEquals(1, settlementList.get(0)
					.get("SettlementStatus"), "验证SettlementStatus 为1");
			Logger.verifyEquals(3, settlementList.get(0).get("BusinessType"),
					"验证BusinessType 为3");
			Logger.verifyEquals(
					(BigDecimal) ymtOrders.get(0).get("fYmtCouponAmount"),
					(BigDecimal) settlementList.get(0).get("CouponAmount"),
					"验证退款结算单退回的平台CouponAmount");
			Logger.verifyEquals(totalPrice1, ymtActList.get(0).getAmount(),
					"验证用户账户流水表取消订单退回用户支付的余额");

			Logger.comment("退第2个订单:" + orderId2);
			cancelorderbean.setOrderId(orderId2);
			// 发送请求
			cancelordercall.setData(false, cancelorderbean);
			cancelordercall.callService();
			Thread.sleep(3000);
			settlementList = database.selectYmtSettlementInvoice(orderId2);
			// 订单主表
			ymtOrders = database.selectOrderByOderId(orderId2);
			// 资金流水表
			ymtActList = new AccountDefaultWapper()
					.selectAccountEntryByUserId(userId);
			listCoupon1 = ymtCoupon.selectBysCouponCode(ymtCouponCode);
			listCoupon2 = ymtCoupon.selectBysCouponCode(sellerCouponCode1);
			Logger.verifyEquals(12,
					new DefaultWapper().getTradingStatus(orderId2), "验证订单交易状态");
			Logger.verifyEquals(
					1,
					new DefaultWapper()
							.selectOrderTradingStatusByOrderIdAndTradingStatus(
									orderId2, 12).size(),
					"验证TradingStatus表中 增加一条订单操作记录");
			Logger.verifyEquals(1, new DefaultWapper()
					.selectOrderReasonByOrderIdAndUserId(orderId2, userId)
					.size(), "验证Ymt_OrderReason表中增加一条订单取消原因记录");
			Logger.verifyEquals(ymtBeforeCount, listCoupon1.get(0)
					.getiCouponUsedCount(), "验证同一主单下,订单全部取消。ymt平台优惠券退回");
			Logger.verifyEquals(sellerBeforeCount + 1, listCoupon2.get(0)
					.getiCouponUsedCount(), "验证同一主单下,买手下所有订单全部取消,商家优惠券退回");

			Logger.verifyEquals(totalPrice2, (BigDecimal) settlementList.get(0)
					.get("CashAmount"), "验证退款金额是否等于付款金额");
			Logger.verifyEquals(1, settlementList.get(0).get("SettlementUser"),
					"验证SettlementUser 为1");
			Logger.verifyEquals(1, settlementList.get(0)
					.get("SettlementStatus"), "验证SettlementStatus 为1");
			Logger.verifyEquals(3, settlementList.get(0).get("BusinessType"),
					"验证BusinessType 为3");
			Logger.verifyEquals(
					(BigDecimal) ymtOrders.get(0).get("fYmtCouponAmount"),
					(BigDecimal) settlementList.get(0).get("CouponAmount"),
					"验证退款结算单退回的平台CouponAmount");
			Logger.verifyEquals(totalPrice2, ymtActList.get(0).getAmount(),
					"验证用户账户流水表取消订单退回用户支付的余额");

			Logger.comment("退第3个订单:" + orderId3);
			cancelorderbean.setOrderId(orderId3);
			// 发送请求
			cancelordercall.setData(false, cancelorderbean);
			cancelordercall.callService();

			settlementList = database.selectYmtSettlementInvoice(orderId3);
			// 订单主表
			ymtOrders = database.selectOrderByOderId(orderId3);
			// 资金流水表
			ymtActList = new AccountDefaultWapper()
					.selectAccountEntryByUserId(userId);
			listCoupon1 = ymtCoupon.selectBysCouponCode(ymtCouponCode);
			listCoupon2 = ymtCoupon.selectBysCouponCode(sellerCouponCode1);
			List<YmtCouponPrivateUserBound> listCoupon3 = ymtCoupon
					.selectBysCouponCode(sellerCouponCode2);
			Logger.verifyEquals(12,
					new DefaultWapper().getTradingStatus(orderId3), "验证订单交易状态");
			Logger.verifyEquals(
					1,
					new DefaultWapper()
							.selectOrderTradingStatusByOrderIdAndTradingStatus(
									orderId3, 12).size(),
					"验证TradingStatus表中 增加一条订单操作记录");
			Logger.verifyEquals(1, new DefaultWapper()
					.selectOrderReasonByOrderIdAndUserId(orderId3, userId)
					.size(), "验证Ymt_OrderReason表中增加一条订单取消原因记录");
			Logger.verifyEquals(ymtBeforeCount, listCoupon1.get(0)
					.getiCouponUsedCount(),
					"验证同一主单下多个商家订单,即使所有订单全部取消。ymt平台优惠券不退回");
			Logger.verifyEquals(sellerBeforeCount + 1, listCoupon3.get(0)
					.getiCouponUsedCount(), "验证同一主单下,买手下所有订单全部取消,商家优惠券退回");

			Logger.verifyEquals(totalPrice3, (BigDecimal) settlementList.get(0)
					.get("CashAmount"), "验证退款金额是否等于付款金额");
			Logger.verifyEquals(1, settlementList.get(0).get("SettlementUser"),
					"验证SettlementUser 为1");
			Logger.verifyEquals(1, settlementList.get(0)
					.get("SettlementStatus"), "验证SettlementStatus 为1");
			Logger.verifyEquals(3, settlementList.get(0).get("BusinessType"),
					"验证BusinessType 为3");
			Logger.verifyEquals(
					(BigDecimal) ymtOrders.get(0).get("fYmtCouponAmount"),
					(BigDecimal) settlementList.get(0).get("CouponAmount"),
					"验证退款结算单退回的平台CouponAmount");
			Logger.verifyEquals(totalPrice3, ymtActList.get(0).getAmount(),
					"验证用户账户流水表取消订单退回用户支付的余额");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_022() {
		Logger.start(true, "取消订单,不退公共优惠券");
		try {
			int userId = Integer.valueOf(EnvSetup.getData("BuyUserId"));
			int sellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
			// 创建订单
			Logger.comment("前置数据准备");
			OrderCallService orderService = new OrderCallService();
			Map map = placeOrder4();
			int orderId = (Integer) map.get("orderId");
			int tradingId = (Integer) map.get("tradingId");
			int ymtBeforeCount = (Integer) map.get("ymtBeforeCount");
			int sellerBeforeCount = (Integer) map.get("sellerBeforeCount");
			String ymtCouponCode = (String) map.get("ymtCouponCode");
			String sellerCouponCode = (String) map.get("sellerCouponCode");

			BigDecimal totalPrice = orderService
					.getNeedPrePayAmountOfCash(orderId);
			// 买家付款
			orderService.orderPayRequest(userId, totalPrice, tradingId);
			// 接单
			// orderService.acceptOrder(orderId, sellerId);
			Logger.comment("前置数据准备结束");
			String cancelReason = "自动化测试取消订单";
			cancelorderbean.setCancelReason(cancelReason);
			cancelorderbean.setCancelType(CancelOrderTypeEnum.BuyerCancelOrder);
			cancelorderbean.setOrderId(orderId);
			cancelorderbean.setUserId(userId);
			// 发送请求
			cancelordercall.setData(cancelorderbean);
			cancelordercall.callService();
			// 数据库验证
			YmtCouponPrivateUserBoundWapper ymtCoupon = new YmtCouponPrivateUserBoundWapper();

			List<Map> couponPublicUsed = new YmtCouponWapper()
					.selectYmtCouponPublicUsed(ymtCouponCode, userId);
			int count = (Integer) couponPublicUsed.get(0).get(
					"iCouponUsedCount");
			List<YmtCouponPrivateUserBound> listCoupon2 = ymtCoupon
					.selectBysCouponCode(sellerCouponCode);
			// 查询交易，退款同步表
			DefaultWapper database = new DefaultWapper();
			List<Map> settlementList = database
					.selectYmtSettlementInvoice(orderId);
			// 订单主表
			List<Map> ymtOrders = database.selectOrderByOderId(orderId);
			// 资金流水表
			List<YmtAccountEntry> ymtActList = new AccountDefaultWapper()
					.selectAccountEntryByUserId(userId);

			Logger.verifyEquals(12,
					new DefaultWapper().getTradingStatus(orderId), "验证订单交易状态");
			Logger.verifyEquals(
					1,
					new DefaultWapper()
							.selectOrderTradingStatusByOrderIdAndTradingStatus(
									orderId, 12).size(),
					"验证TradingStatus表中 增加一条订单操作记录");
			Logger.verifyEquals(1, new DefaultWapper()
					.selectOrderReasonByOrderIdAndUserId(orderId, userId)
					.size(), "验证Ymt_OrderReason表中增加一条订单取消原因记录");
			Logger.verifyEquals(ymtBeforeCount, count, "验证ymt平台短码优惠券不退回");
			Logger.verifyEquals(sellerBeforeCount + 1, listCoupon2.get(0)
					.getiCouponUsedCount(), "验证商家优惠券退回");

			Logger.verifyEquals(totalPrice, (BigDecimal) settlementList.get(0)
					.get("CashAmount"), "验证退款金额是否等于付款金额");
			Logger.verifyEquals(1, settlementList.get(0).get("SettlementUser"),
					"验证SettlementUser 为1");
			Logger.verifyEquals(1, settlementList.get(0)
					.get("SettlementStatus"), "验证SettlementStatus 为1");
			Logger.verifyEquals(3, settlementList.get(0).get("BusinessType"),
					"验证BusinessType 为3");
			Logger.verifyEquals(
					(BigDecimal) ymtOrders.get(0).get("fYmtCouponAmount"),
					(BigDecimal) settlementList.get(0).get("CouponAmount"),
					"验证退款结算单退回的平台CouponAmount");
			Logger.verifyEquals(totalPrice, ymtActList.get(0).getAmount(),
					"验证用户账户流水表取消订单退回用户支付的余额");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_023() {
		Logger.start(true, "订单已支付(余额+支付宝组合支付)商家未接单,买家取消订单成功");
		try {
			// 创建订单
			OrderCallService orderService = new OrderCallService();
			Logger.comment("前置数据准备");
			PlaceOrderResp placeOrderResp = new OrderCallService()
					.createM2cOrder();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额
			Logger.comment("前置数据准备结束");
			BigDecimal blanceAmout = new BigDecimal(5);
			// 支付订单
			int thirdTradingId = new OrderCallService().orderPayRequest(userId,
					blanceAmout, tradingId, "15");

			PayGateWayCallService.notifyCall("15",
					String.valueOf(thirdTradingId),
					totalPrice.subtract(blanceAmout).toString(), userId);
			Logger.comment("前置数据准备结束");
			String cancelReason = "自动化测试取消订单";
			cancelorderbean.setCancelReason(cancelReason);
			cancelorderbean.setCancelType(CancelOrderTypeEnum.BuyerCancelOrder);
			cancelorderbean.setOrderId(orderId);
			cancelorderbean.setUserId(userId);
			// 发送请求
			cancelordercall.setData(cancelorderbean);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");
			// 数据库验证
			DefaultWapper database = new DefaultWapper();
			Logger.verifyEquals(12, database.getTradingStatus(orderId),
					"验证订单交易状态");
			Logger.verifyEquals(
					1,
					database.selectOrderTradingStatusByOrderIdAndTradingStatus(
							orderId, 12).size(), "验证TradingStatus表中 增加一条订单操作记录");
			Logger.debug(database.selectOrderReasonByOrderIdAndUserId(orderId,
					userId).get(0));
			Logger.verifyEquals(1, database
					.selectOrderReasonByOrderIdAndUserId(orderId, userId)
					.size(), "验证Ymt_OrderReason表中增加一条订单取消原因记录");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CancelOrder_024() {
		Logger.start(true, "订单已支付(余额+支付宝组合支付)商家未接单,买家取消订单成功");
		try {
			// 创建订单
			OrderCallService orderService = new OrderCallService();
			Logger.comment("前置数据准备");
			PlaceOrderResp placeOrderResp = new OrderCallService()
					.createM2cOrder();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额
			Logger.comment("前置数据准备结束");
			BigDecimal blanceAmout = new BigDecimal(5);
			// 支付订单
			int thirdTradingId = new OrderCallService().orderPayRequest(userId,
					blanceAmout, tradingId, "15");

			PayGateWayCallService.notifyCall("15",
					String.valueOf(thirdTradingId),
					totalPrice.subtract(blanceAmout).toString(), userId);
			Logger.comment("前置数据准备结束");
			String cancelReason = "自动化测试取消订单";
			cancelorderbean.setCancelReason(cancelReason);
			cancelorderbean.setCancelType(CancelOrderTypeEnum.BuyerCancelOrder);
			cancelorderbean.setOrderId(orderId);
			cancelorderbean.setUserId(userId);
			// 发送请求
			cancelordercall.setData(cancelorderbean);
			cancelordercall.callService();
			Logger.verifyEquals(ECode.SUCCESS, cancelordercall.getCode(),
					"验证Code");
			// 数据库验证
			DefaultWapper database = new DefaultWapper();
			Logger.verifyEquals(12, database.getTradingStatus(orderId),
					"验证订单交易状态");
			Logger.verifyEquals(
					1,
					database.selectOrderTradingStatusByOrderIdAndTradingStatus(
							orderId, 12).size(), "验证TradingStatus表中 增加一条订单操作记录");
			Logger.debug(database.selectOrderReasonByOrderIdAndUserId(orderId,
					userId).get(0));
			Logger.verifyEquals(1, database
					.selectOrderReasonByOrderIdAndUserId(orderId, userId)
					.size(), "验证Ymt_OrderReason表中增加一条订单取消原因记录");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}
